﻿using System;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using Framework.Library.Base.Base;
using Framework.Library.Base.Extensions;
using Framework.Library.Data.DAL;
using Framework.Library.Data.DAO;
using System.Linq;
using Framework.Library.Core.Utils.GlobalHelper;
using Framework.Library.Data.DAL.JObject;
using Framework.Library.Core.Config;

namespace Framework.Portal.Layouts.Client.Modules.Menu
{
    public partial class AdsList : BaseControl
    {
        public AdsList()
        {
        }

        public AdsList(JSection section)
        {
            if(!string.IsNullOrEmpty(section.parameter))
                arrParams = section.parameter.Split(',').ToList<string>();
            MENUNAME = section.title;
        }
        public string MENUNAME = string.Empty;
        protected List<string> arrParams = new List<string>();

        protected static int portalId = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if(arrParams.Count > 0)
                {
                    List<ADSItem> lstAds = ManagerFactory.AdsManager.GetList(arrParams);
                    if (lstAds.Count > 0)
                    {
                        rptContent.DataSource = lstAds;
                        rptContent.DataBind();
                    }
                }
            }
        }
        protected void rptContent_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var info = (ADSItem)e.Item.DataItem;
                var imgAds = (Image)e.Item.FindControl("imgAds");
                var hplLinkAds = (HyperLink)e.Item.FindControl("hplLinkAds");
                imgAds.ImageUrl = info.SOURCE;
                hplLinkAds.NavigateUrl = Configurations.ROOTDIR + "Resources.ashx?action=ads&id=" + info.ID;
            }
        }
    }
}